<template>
  <div class="base-echart">
    <div
      ref="echartDivRef"
      :style="{ width: props.width, height: props.height }"
    ></div>
  </div>
</template>

<script lang="ts" setup>
import { defineProps, onMounted, ref, watchEffect } from 'vue'
import useEchart from '../hooks/useEchart'
const props = defineProps({
  width: {
    type: String,
    default: '100%'
  },
  height: {
    type: String,
    default: '360px'
  },
  options: {
    type: Object,
    required: true
  }
})

const echartDivRef = ref<HTMLElement>()

onMounted(() => {
  const { setOptions } = useEchart(echartDivRef.value!)

  watchEffect(() => {
    setOptions(props.options)
  })
})
</script>

<style></style>
